﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class admin_newsEdit : System.Web.UI.Page
{
    public string id = "";
    public string lanmuName = "";
    public string channelid = "";
    public string newName = "";
    public string tourl = "";
    public string sour = "";
    public string datestr = "";
    public string content = "";
    public string img = "";
    public string files = "";
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            init();
        }
    }
    public void init() {
        if (Request["id"] != null && Request["id"].ToString().Trim().Length > 0) id = Request["id"].ToString();
        //如果有id则初始化
        if (id.ToString().Trim().Length > 0) { 
            //提取这条信息
            DataTable dt = DB.getDataTable("select * from news where newId=" + id);
            if (dt != null && dt.Rows.Count > 0) { 
                //获取栏目
                channelid = dt.Rows[0]["channelid"].ToString();
                DataTable channelDt = DB.getDataTable("select * from channel where channel_id=" + channelid);
                if (channelDt != null && channelDt.Rows.Count > 0) {
                    lanmuName = channelDt.Rows[0]["name"].ToString();
                }
                newName = dt.Rows[0]["title"].ToString();
                tourl = dt.Rows[0]["tourl"].ToString();
                sour = dt.Rows[0]["source"].ToString();
                datestr = dt.Rows[0]["addDate"].ToString();
                content = dt.Rows[0]["content"].ToString();
                //contentFck.Value = dt.Rows[0]["content"].ToString();
                img = dt.Rows[0]["img"].ToString();
                files = dt.Rows[0]["filePath"].ToString();
            }
        }
    }
    //获取树
    public void getTree() {
        StringBuilder sb = new StringBuilder();
        if (Session["admin"] != null && (Session["admin"].ToString().Equals("qiang") || Session["admin"].ToString().Equals("admin")))
        {
            DataTable dt = DB.getDataTable("select * from channel ");
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    sb.Append("tree.nodes[\"" + dt.Rows[i]["father_id"].ToString() + "_" + dt.Rows[i]["channel_id"].ToString() + "\"] = \"text:" + dt.Rows[i]["name"].ToString() + ";method:sa('" + dt.Rows[i]["channel_id"].ToString() + "','" + dt.Rows[i]["name"].ToString() + "')\";");
                }
            }
        }
        else {
            DataTable dt = DB.getDataTable("select * from channel where channel_id in (select channelid from admin_qx where adminId=" + Session["adminId"] + ")");
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    sb.Append("tree.nodes[\"1_" + dt.Rows[i]["channel_id"].ToString() + "\"] = \"text:" + dt.Rows[i]["name"].ToString() + ";method:sa('" + dt.Rows[i]["channel_id"].ToString() + "','" + dt.Rows[i]["name"].ToString() + "')\";");
                }
            }
        }
        Response.Write(sb.ToString());
    }
}
